/**
 * 依赖全局变量 InfoGlobal
 * Created by shopnc on 2015/11/26.
 */
//定义表格
var dtGridColumns = [
    {
        id: 'delFlag',
        type: 'int',
        'export':false,
        hideQuery:true,
        hideQueryType:'eq',
        hideQueryValue:1,
        hide:true
    },
    {
        id: 'type',
        type: 'int',
        'export':false,
        hideQuery:true,
        hideQueryType:'eq',
        hideQueryValue:1,
        hide:true
    },
    {
        id: 'registerTime',
        title: '操作时间',
        type: 'date',
        format: 'yyyy-MM-dd',
        headerClass: 'text-center',
        columnClass: 'text-center',
        fastSort: false,
        fastQuery: true,
        fastQueryType: 'range'
    },
    {
        id: 'userNum',
        type: 'number',
        title: '注册用户数量',
        headerClass: 'text-center',
        columnClass: 'text-center',
        fastSort: false,
        fastQuery: false
    },
    {
        id: 'rechargeNum',
        type: 'number',
        title: '充值用户数量',
        headerClass: 'text-center',
        columnClass: 'text-center',
        fastSort: false,
        fastQuery: false
    } ,
    {
        id: 'scaleRec',
        type: 'number',
        title: '注册-充值转化率',
        headerClass: 'text-center',
        columnClass: 'text-center',
        fastSort: false,
        fastQuery: false
    },
    {
        id: 'totalAmo',
        type: 'number',
        title: '总充值金额',
        headerClass: 'text-center',
        columnClass: 'text-center',
        fastSort: false,
        fastQuery: false
    } ,
    {
        id: 'averageAmo',
        type: 'number',
        title: '人均充值金额',
        headerClass: 'text-center',
        columnClass: 'text-center',
        fastSort: false,
        fastQuery: false
    }
];
var dtGridOption = {
    lang: 'zh-cn',
    ajaxLoad: true,
    loadURL: ncGlobal.adminRoot + 'user/json/form',
    exportURL: ncGlobal.adminRoot + 'userFrom/json/export',
    exportFileName: '用户来源报表',
    columns: dtGridColumns,
    gridContainer: 'dtGridContainer',
    toolbarContainer: 'dtGridToolBarContainer',
    tools: 'refresh|faseQuery|export[excel]',
    pageSize: 10,
    pageSizeLimit: [10, 20, 50],
    ncColumnsType: {int: ["id","agentId","delFlag"], Timestamp: ["createTime"]}
};
var grid = $.fn.DtGrid.init(dtGridOption);
grid.fastQueryParameters = new Object();
grid.fastQueryParameters['eq_delFlag'] = 1;
grid.sortParameter.columnId = ['desc_createTime'];

var information = function () {
    /**
     * 事件绑定
     * @private
     */
    function _bindEvent() {
        //模糊搜索
        $('#customSearch').click(function () {
            grid.fastQueryParameters = new Object();
            grid.fastQueryParameters['lk_ip_or_lk_uri'] = $('#keyword').val();
            grid.fastQueryParameters['eq_delFlag'] = 1;
            grid.sortParameter.columnId=['desc_createTime'];
            grid.pager.startRecord = 0;
            grid.pager.nowPage = 1;
            grid.pager.recordCount = -1;
            grid.pager.pageCount = -1;
            grid.refresh(true);
        });

        //去除输入框回车键提交
        $("input").on("keydown", function (e) {
            if (e.keyCode == 13) {
                e.preventDefault();
                var a = $("#releasePrice");
                a.length && a.trigger("click");
            }
        });

        $("#addForm").on("nc.formSubmit.success", function (e) {
        });

    }

    function _doStat() {
        grid.fastQueryParameters = new Object();
        grid.fastQueryParameters['eq_delFlag'] = 1;
        grid.fastQueryParameters['eq_type'] = 1;
        if($("#source option:selected").val() !=''){
            grid.fastQueryParameters['eq_source'] = $("#source option:selected").val();
        }
        grid.sortParameter.columnId = ['desc_createTime'];
        grid.pager.startRecord = 0;
        grid.pager.nowPage = 1;
        grid.pager.recordCount = -1;
        grid.pager.pageCount = -1;
        grid.refresh(true);
    }

    //外部可调用
    return {
        init: function () {
            _bindEvent();
        },
        doStat:_doStat
    }
}()
$(function () {
    grid.load();
    information.init();
    $("#statistics").append('<a href="javascript:;"  class="btn btn-danger btn-sm m-r-10" onclick="information.doStat()"><i class="fa fa-calculator"></i>&nbsp;统计&nbsp;</a>');
})

